Python Forum
Small game (school project)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small game (school project)
#1
Hello,

I am not a native speaker...

I have been assigned to a group of 5 students. We have had an introduction to python last year (30h theory + 30h on PC, approximately) and now we have to create a game.

We use python, tkinter

Many groups have choosen to replicate an existing game... but I suggested to create one, to develop the game based on what we have learned rather than "go fetch". We have to establish the project by the end of the week and realize it within two months. The conception is done, but then we have to write the program.

So, it is a single window project, with a map (7*7 tiles), a menu bar and a text-display bar, below; a menu would be nice, if we manage to create save files, but won't be the first focus. We will probably not create an AI, so it will be 2 players.

Tiles generate an income, based on displayed values. With this income, units (3 types) can be built, from specific base-tiles. And there are extra-income on some tiles, allowing to gather magic (temp boosts to units). The units must destroy the other base and conquer the tiles to increase income.

It's quite simple, might not be much more fun than OXO, but we will stick to our level... we are studying electromechanics, not computer science...

So, my first problem is with canvas...

[color=#2c3e50]import Tkinter

window = Tkinter.Tk()

display = Canvas(window, width=1500, height=900)
display.create_rectangle(25, 25, 1100, 600, fill="grey")
display.create_rectangle(1125, 25, 1475, 600, fill="blue")
display.create_rectangle(25, 625, 1475, 875, fill="white")
display.pack()

window.mainloop()[/color]
Earlier this afternoon, python did not identity 'Canvas' : not defined. Later on, it worked and it displayed the three coloured rectangles, well placed. And now, "canvas is undefined"... again...

Huh







Reply
#2
import Tkinter as tk

color =  '#2c3e50'

window = tk.Tk()

display = tk.Canvas(window, width=1500, height=900)
display.create_rectangle(25, 25, 1100, 600, fill="grey")
display.create_rectangle(1125, 25, 1475, 600, fill="blue")
display.create_rectangle(25, 625, 1475, 875, fill="white")
display.pack()

window.mainloop()
Reply
#3
Sorry for this wrong input...

So, I tested canvas() again, this morning, and python failed again to define it... is it an unstable code or... I don't get it, as it did work a couple times during a session, yesterday, before Kernel died and was resurrected, again...

But anyways, not really concerned about canvas, and maybe it is not the good method. The teacher will probably explain this later on, but I know we will have a lot of work in 2 months and that I'd better do this task now...

What is the best method to create the following 3 zones on a window :

1) a map, with tiles, where units can be created and move
2) a menu/options zone, with buttons
3) a text display, below the two other zones

:)
Reply
#4
Try the changes I show you above. They work.
You had syntax errors in original code
Reply
#5
Hello,

We have had an electricity exam, just two days ago, so I left this aside...

But thanx for the corrections. It seems to me a problem is that the teacher uses a reference book and I guess the syntax evolved in the mean time...

from Tkinter import *
fen1 = Tk()
tex1 = Label(fen1, text='Bonjour tout le monde !', fg='red')
tex1.pack()
bou1 = Button(fen1, text='Quitter', command = fen1.destroy)
bou1.pack()
fen1.mainloop()
This is one example of a code given to introduce classes and widgets... and Python does it, but does not like the code and puts yellow triangles everywhere, with this message:
"x" may be undefined or defined from star imports : Tkinter.

import Tkinter as tk
fen1 = tk.Tk()
tex1 = tk.label(fen1, text='Bonjour tout le monde !', fg='red')
tex1.pack()
bou1 = tk.button(fen1, text='Quitter', command = fen1.destroy)
bou1.pack()
fen1.mainloop()
Seems much better!

This to maintain the thread and see if the others from the group will get to work, since I don't want to do it in the last days...
Reply
#6
I don't know why teachers are still using python 2.7 as it is only going to be supported
for another couple of years, and python is now at 3.6.3.
At any rate, tk.button needs to be tk.Button
tk.label needs to be  tk.Label
Reply
#7
Quote:
from Tkinter import *
That's probably your issue right there.  Canvas is part of the Tkinter package, so when you import * it works, but when you do import Tkinter as tk then it doesn't work anymore, as you'd need to reference it as tk.Canvas instead.
Reply
#8
Hello,

We have tons of things to do... and this project on the side that needs continuous work... Others are beginning to understand it will need more than a week-end, but so far, I came up with this...

The main background is set and the "quit" option works. It is thus an acceptable program... hum hum... Cool


import Tkinter as tk
 
color =  '#2c3e50'

Francais = ["Nouvelle partie", "Sauver", "Charger", "Quitter", "Changer de langue", "Aide"]

#crea fen
window = tk.Tk()
#change tk pour titre
window.title("Bathathaï") 
#crea canvas
display = tk.Canvas(window, width=1280, height=720)
#affichage fond carte (remplacer par image le fond) 
carte = display.create_rectangle(25, 50, 676, 701, fill="grey") # 93*7 
#affichage grille
xa = 35
ya = 60
for i in range(8):
    display.create_line(xa, ya, xa, ya + 630)
    xa += 90
xa = 35 #reset xa
for i in range(8):
    display.create_line(xa, ya, xa + 630, ya)
    ya += 90

#affichage fond menu
menu = display.create_rectangle(700, 50, 1250, 350, fill="blue")
#affichage fond texte
affichage = display.create_rectangle(700, 375, 1250, 700, fill="white")
#packing dcanvas display
display.pack()

#bouton quitter + placement
button1 = tk.Button(window, text = Francais[3], command = window.destroy)
button1.place(x=1075, y = 100)

#mainloop
window.mainloop()
The next step is quite crucial. I want to create the working coordinates of the map. Movements will be only NWSE, one tile at the time, and we will need to be able to cast spells on units. Is there a simple method for that or do I need to create a list of tupples with 49 coordinates?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my python project for school vavervirus 2 600 Oct-12-2023, 03:28 AM
Last Post: buran
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,255 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  Need some help with Dice Game for daughter in school OptX 2 1,894 Feb-12-2021, 08:43 PM
Last Post: BashBedlam
  School project janivar91 3 2,646 Jan-23-2021, 06:31 AM
Last Post: KonohaHokage
  problem on creating a small game nayo43 5 2,699 Dec-13-2020, 01:03 PM
Last Post: jefsummers
  Python School Project andreas30298 2 2,101 Nov-12-2020, 09:58 AM
Last Post: Axel_Erfurt
  Guidance on solving an "if else loop" in this small project ando 5 2,675 Mar-27-2020, 10:56 PM
Last Post: ando
  I need help for a school project IndyNeerhoff 1 2,039 Sep-28-2019, 08:28 PM
Last Post: Gribouillis
  [Tkinter] Tkinter project school Kersow 2 2,444 Apr-08-2019, 08:45 PM
Last Post: Larz60+
  card dealer school project kalle1234 5 9,603 Jan-05-2019, 09:21 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020