Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Here's a Civilization type game I made
New Posts  All Forums:Forum Nav:

Here's a Civilization type game I made

post #1 of 30
Thread Starter 
I just finished a software modelling course, and for our final project we had to write a civilization clone.

But its over now, and it seems like such a waste to just discard all of that hard work without anyone ever actually getting to play it.

Its pretty sparse gameplay wise but there is gameplay, as well as multiple players, a win condition, saving/loading and some rudimentary AI (beware the deer)

It was a 4 person group, but I ended up writting 46% of the 8000 lines of code that went into the game.

But since my team mates were just software engineers and I'm in Comp Sci with the graphics and gaming focus that means its only 46% as good as it should be.

My teammates wrote some poorly designed, slow code, and I had to refrain from fixing it, because not only did they get a little testy every time they looked at the SVN log and found I had completely re-written one of their methods the prof said he would dock marks if everyone didn't pull their own weight.

As a result, the whole thing is kind of fragile, and everyone has their own methods for moving the map, creating units etc..





The graphics were provided with the assignment, and come from an inactive Civ clone called Civ Quest. They're GPL'd though so its not plagiarism.


Download link: http://www.megaupload.com/?d=WZPFLT2Q

Its an executable jar file, so you'll need the Java Runtime Environment and you should be able to just double click to run it.

It runs on Linux too, and probably OSX, but I've only tested Linux.

If you can't double click it then you can run it from the command line using

Code:
java -jar ACiv.jar
Just like you would for Minecraft.

Its fairly resource heavy though, since one of my team members thought it would be a good idea to have every tile load the entire sprite sheet, which means it takes up 350mb in memory, even though the jar is 200kb, and it actually gets a little slow at 1920x1080, which is why I've locked the resolution to 1024x768.
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
post #2 of 30
Im impressed

The most I ever did was in Basic and that was a lablel printing program
post #3 of 30
Great work.
The Kandalf
(16 items)
 
  
CPUMotherboardGraphicsGraphics
I7 5820K MSI X99S Gaming 7 ASUS R9 280X TOP Crossfire X ASUS R9 280X TOP Crossfire X 
RAMHard DriveOptical DriveOS
Crucial DDR4 2133MHz 8GB (2x4GB) Samsung SpinPoint F1 1TB HP DVD630 Ubuntu 
MonitorKeyboardPowerCase
2x Philips Brilliance 220CW Microsoft Wireless Desktop Elite Keyboard Fractal Design Newton R3, 800W 80+ Platinum Corsair 900D 
MouseMouse PadAudioAudio
Mionix Naos 8200 Razer Pro Solutions Arcam rDAC B&W CM1 
  hide details  
Reply
The Kandalf
(16 items)
 
  
CPUMotherboardGraphicsGraphics
I7 5820K MSI X99S Gaming 7 ASUS R9 280X TOP Crossfire X ASUS R9 280X TOP Crossfire X 
RAMHard DriveOptical DriveOS
Crucial DDR4 2133MHz 8GB (2x4GB) Samsung SpinPoint F1 1TB HP DVD630 Ubuntu 
MonitorKeyboardPowerCase
2x Philips Brilliance 220CW Microsoft Wireless Desktop Elite Keyboard Fractal Design Newton R3, 800W 80+ Platinum Corsair 900D 
MouseMouse PadAudioAudio
Mionix Naos 8200 Razer Pro Solutions Arcam rDAC B&W CM1 
  hide details  
Reply
post #4 of 30
A+ grade job mate.
My system (AMD)
(14 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X4 955 BE "Deneb" @ 3415Mhz Gigabyte GA-MA790X-DS4 (1x) Gigabyte AMD Radeon 5770 Kingston HyperX DDR2 1066 4GB 
Hard DriveOSMonitorKeyboard
2x 500GB, 1x 1TB external Windows 7 Ultimate Deep Blue 32bit 1x Asus VE248H 24" Monitor Tt eSPORTS Challenger Gaming Keyboard 
PowerCaseMouseMouse Pad
Thermaltake 550w Aero Cool Syclone II Logitech MX518 1800DPI Red Mousepad 
Audio
Creative Headphones 
  hide details  
Reply
My system (AMD)
(14 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X4 955 BE "Deneb" @ 3415Mhz Gigabyte GA-MA790X-DS4 (1x) Gigabyte AMD Radeon 5770 Kingston HyperX DDR2 1066 4GB 
Hard DriveOSMonitorKeyboard
2x 500GB, 1x 1TB external Windows 7 Ultimate Deep Blue 32bit 1x Asus VE248H 24" Monitor Tt eSPORTS Challenger Gaming Keyboard 
PowerCaseMouseMouse Pad
Thermaltake 550w Aero Cool Syclone II Logitech MX518 1800DPI Red Mousepad 
Audio
Creative Headphones 
  hide details  
Reply
post #5 of 30
Ouch, sounds like you had a rough time with the people on your project. That sucks, still, cool project.
Shinobu
(16 items)
 
Nodoka
(16 items)
 
Index
(4 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Asus P8Z77-I Deluxe HD6450 Flex Crucial 16GB (2x 8GB) Ballistix Elite 
Hard DriveHard DriveOSMonitor
Samsung SSD 840 EVO 250GB TOSHIBA DT01ACA300 Arch Linux Dell UltraSharp U2713HM 
MonitorMonitorKeyboardPower
Dell U2410 Dell 2407WFP Cherry - Cherry Blue Switches (Unlabeled keys) Seasonic X-650 
CaseMouseAudioAudio
BitFenix Prodigy Black Logitech M570 Trackball Sennheiser HD595 Creative GigaWorks T20 
CPUMotherboardGraphicsRAM
Intel Core i5 3570K Zotac Z77-ITX WiFi EVGA 680 GTX Samsung 
Hard DriveHard DriveOSMonitor
Samsung 256GB 830 Samsung SpinPoint HD501LJ Windows 7 Dell U2410 
MonitorMonitorKeyboardCase
Dell 2407WFP Dell E248WFP Cherry Black (MX Blue Switches, Blank Keys) Silverstone Sugi SG08B 
MouseAudioAudio
Logitech Trackman Logitech Z-5500 Sennheiser HD595s 
CPUMotherboardRAMHard Drive
AMD Athlon II X2 240e Asus M5A78L-M/USB3 Crucial 8GB (2x4GB) DDR3 1600Mhz Ballistix Sport 1.5TB Hard Drives 
  hide details  
Reply
Shinobu
(16 items)
 
Nodoka
(16 items)
 
Index
(4 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Asus P8Z77-I Deluxe HD6450 Flex Crucial 16GB (2x 8GB) Ballistix Elite 
Hard DriveHard DriveOSMonitor
Samsung SSD 840 EVO 250GB TOSHIBA DT01ACA300 Arch Linux Dell UltraSharp U2713HM 
MonitorMonitorKeyboardPower
Dell U2410 Dell 2407WFP Cherry - Cherry Blue Switches (Unlabeled keys) Seasonic X-650 
CaseMouseAudioAudio
BitFenix Prodigy Black Logitech M570 Trackball Sennheiser HD595 Creative GigaWorks T20 
CPUMotherboardGraphicsRAM
Intel Core i5 3570K Zotac Z77-ITX WiFi EVGA 680 GTX Samsung 
Hard DriveHard DriveOSMonitor
Samsung 256GB 830 Samsung SpinPoint HD501LJ Windows 7 Dell U2410 
MonitorMonitorKeyboardCase
Dell 2407WFP Dell E248WFP Cherry Black (MX Blue Switches, Blank Keys) Silverstone Sugi SG08B 
MouseAudioAudio
Logitech Trackman Logitech Z-5500 Sennheiser HD595s 
CPUMotherboardRAMHard Drive
AMD Athlon II X2 240e Asus M5A78L-M/USB3 Crucial 8GB (2x4GB) DDR3 1600Mhz Ballistix Sport 1.5TB Hard Drives 
  hide details  
Reply
post #6 of 30
Looks amazing for a single semester and only a few programmers. Hopefully the other programmers learned something from their individual weaknesses.
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
post #7 of 30
Thread Starter 
Quote:
Originally Posted by lordikon View Post
Looks amazing for a single semester and only a few programmers. Hopefully the other programmers learned something from their individual weaknesses.

Wasn't a single semester, it was 3 weeks. I think they did learn a few things. Some of their code was worrying:

Code:
public String determineDirection(int x, int y)
    {
        String direction = "none";

        if ((y > 0) && (y < model.map.TILESIZE) && ((x > model.map.TILESIZE) && (x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE))))
        {
            //System.out.println("northeast");
            //System.out.println(model.mv.vx+model.mv.vw);
            direction = "northeast";
            if (model.mv.vy == -5)
            {
                //System.out.println("east special");
                direction = "east";
            }
            else if (!(model.mv.vy == -5) && ((model.mv.vx+model.mv.vw) == model.map.width+5))
            {
                //System.out.println("north special");
                direction = "north";
            }
        }
        else if (((y > 0) && (y < model.map.TILESIZE)) && ((x > 0) && (x < model.map.TILESIZE)))
        {
            //System.out.println("northwest");
            direction = "northwest";
            if (model.mv.vy == -5)
            {
                //System.out.println("west special");
                direction = "west";
            }
            else if (!(model.mv.vy == -5) && ((model.mv.vx) == -5))
            {
                //System.out.println("north special");
                direction = "north";
            }
        }
        else if (((y > ((model.mv.vh-1)*model.map.TILESIZE)) && (y < ((model.mv.vh)*model.map.TILESIZE))) && ((x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE))))
        {
            //System.out.println("southeast");
            direction = "southeast";
            if (model.mv.vy+model.mv.vh == model.map.height+5)
            {
                //System.out.println("east special");
                direction = "east";
            }
            else if (!(model.mv.vy+model.mv.vh == model.map.height+5) && (((model.mv.vx+model.mv.vw) == model.map.width+5)))
            {
                //System.out.println("south special");
                direction = "south";
            }
        }
        else if (((y > ((model.mv.vh-1)*model.map.TILESIZE)) && (y < ((model.mv.vh)*model.map.TILESIZE))) && ((x > 0) && (x < model.map.TILESIZE) && ((y > model.map.TILESIZE))))
        {
            //System.out.println("southwest");
            direction = "southwest";
            if (model.mv.vy+model.mv.vh == model.map.height+5)
            {
                //System.out.println("west special");
                direction = "west";
            }
            else if (!(model.mv.vy+model.mv.vh == model.map.height+5) && ((model.mv.vx) == -5))
            {
                //System.out.println("south special");
                direction = "south";
            }
        }
        else if ((y > 0) && (y < model.map.TILESIZE) && ((x > model.map.TILESIZE) && (x < (model.mv.vw-1) * model.map.TILESIZE)))
        {
            //System.out.println("north");
            direction = "north";
        }
        else if ((y > ((model.mv.vh-1)*model.map.TILESIZE)) && (y < ((model.mv.vh)*model.map.TILESIZE)) && ((x > model.map.TILESIZE) && (x < (model.mv.vw-1) * model.map.TILESIZE)))
        {
            //System.out.println("south");
            direction = "south";
        }
        else if ((x > 0) && (x < model.map.TILESIZE) && ((y > model.map.TILESIZE) && (y < (model.map.TILESIZE*(model.mv.vh-1)))))
        {
            //System.out.println("west");
            direction = "west";
        }        
        else if ((x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE)) && ((y > model.map.TILESIZE) && (y < (model.map.TILESIZE*(model.mv.vh-1)))))
        {
            //System.out.println("east");
            direction = "east";
        }
        
        else
        {
            direction = "none";
        }
        
        return direction;
    }
All of that was to determine which edge of the map the cursor was on, so that it could scroll. I replaced it with 6 lines of code that did the same thing. I hope he learned from it.
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
post #8 of 30
Looks awesome.

Just adds to my reasons why I should have majored in comp sci or computer engineering over electrical engineering.... ***
Sexy Sandy
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7-2600K Gigabyte Z68X-UD5 MSI GTX 580 LIGHTNING G.SKILL Ripjaws X Series 8GB (2 x 4GB) 
Hard DriveOptical DriveCoolingOS
Crucial M4 128GB+Samsung Spinpoint F3 1TB+Seaga... LITE-ON DVD Burner Noctua NH-D14 Windows 7 64-bit 
MonitorPowerCaseAudio
BenQ xl2410t Corsair 850HX Cooler Master HAF-X  Asus Xonar DG 
  hide details  
Reply
Sexy Sandy
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7-2600K Gigabyte Z68X-UD5 MSI GTX 580 LIGHTNING G.SKILL Ripjaws X Series 8GB (2 x 4GB) 
Hard DriveOptical DriveCoolingOS
Crucial M4 128GB+Samsung Spinpoint F3 1TB+Seaga... LITE-ON DVD Burner Noctua NH-D14 Windows 7 64-bit 
MonitorPowerCaseAudio
BenQ xl2410t Corsair 850HX Cooler Master HAF-X  Asus Xonar DG 
  hide details  
Reply
post #9 of 30
Quote:
Originally Posted by nathris View Post
Wasn't a single semester, it was 3 weeks. I think they did learn a few things. Some of their code was worrying:

Code:
public String determineDirection(int x, int y)
    {
        String direction = "none";

        if ((y > 0) && (y < model.map.TILESIZE) && ((x > model.map.TILESIZE) && (x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE))))
        {
            //System.out.println("northeast");
            //System.out.println(model.mv.vx+model.mv.vw);
            direction = "northeast";
            if (model.mv.vy == -5)
            {
                //System.out.println("east special");
                direction = "east";
            }
            else if (!(model.mv.vy == -5) && ((model.mv.vx+model.mv.vw) == model.map.width+5))
            {
                //System.out.println("north special");
                direction = "north";
            }
        }
        else if (((y > 0) && (y < model.map.TILESIZE)) && ((x > 0) && (x < model.map.TILESIZE)))
        {
            //System.out.println("northwest");
            direction = "northwest";
            if (model.mv.vy == -5)
            {
                //System.out.println("west special");
                direction = "west";
            }
            else if (!(model.mv.vy == -5) && ((model.mv.vx) == -5))
            {
                //System.out.println("north special");
                direction = "north";
            }
        }
        else if (((y > ((model.mv.vh-1)*model.map.TILESIZE)) && (y < ((model.mv.vh)*model.map.TILESIZE))) && ((x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE))))
        {
            //System.out.println("southeast");
            direction = "southeast";
            if (model.mv.vy+model.mv.vh == model.map.height+5)
            {
                //System.out.println("east special");
                direction = "east";
            }
            else if (!(model.mv.vy+model.mv.vh == model.map.height+5) && (((model.mv.vx+model.mv.vw) == model.map.width+5)))
            {
                //System.out.println("south special");
                direction = "south";
            }
        }
        else if (((y > ((model.mv.vh-1)*model.map.TILESIZE)) && (y < ((model.mv.vh)*model.map.TILESIZE))) && ((x > 0) && (x < model.map.TILESIZE) && ((y > model.map.TILESIZE))))
        {
            //System.out.println("southwest");
            direction = "southwest";
            if (model.mv.vy+model.mv.vh == model.map.height+5)
            {
                //System.out.println("west special");
                direction = "west";
            }
            else if (!(model.mv.vy+model.mv.vh == model.map.height+5) && ((model.mv.vx) == -5))
            {
                //System.out.println("south special");
                direction = "south";
            }
        }
        else if ((y > 0) && (y < model.map.TILESIZE) && ((x > model.map.TILESIZE) && (x < (model.mv.vw-1) * model.map.TILESIZE)))
        {
            //System.out.println("north");
            direction = "north";
        }
        else if ((y > ((model.mv.vh-1)*model.map.TILESIZE)) && (y < ((model.mv.vh)*model.map.TILESIZE)) && ((x > model.map.TILESIZE) && (x < (model.mv.vw-1) * model.map.TILESIZE)))
        {
            //System.out.println("south");
            direction = "south";
        }
        else if ((x > 0) && (x < model.map.TILESIZE) && ((y > model.map.TILESIZE) && (y < (model.map.TILESIZE*(model.mv.vh-1)))))
        {
            //System.out.println("west");
            direction = "west";
        }        
        else if ((x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE)) && ((y > model.map.TILESIZE) && (y < (model.map.TILESIZE*(model.mv.vh-1)))))
        {
            //System.out.println("east");
            direction = "east";
        }
        
        else
        {
            direction = "none";
        }
        
        return direction;
    }
All of that was to determine which edge of the map the cursor was on, so that it could scroll. I replaced it with 6 lines of code that did the same thing. I hope he learned from it.
Hey, thats the beauty of programming. You can achieve the same goal in different ways. Some is easier to read/write, some are faster etc etc. If you got the grade you deserved then no problem.
The Kandalf
(16 items)
 
  
CPUMotherboardGraphicsGraphics
I7 5820K MSI X99S Gaming 7 ASUS R9 280X TOP Crossfire X ASUS R9 280X TOP Crossfire X 
RAMHard DriveOptical DriveOS
Crucial DDR4 2133MHz 8GB (2x4GB) Samsung SpinPoint F1 1TB HP DVD630 Ubuntu 
MonitorKeyboardPowerCase
2x Philips Brilliance 220CW Microsoft Wireless Desktop Elite Keyboard Fractal Design Newton R3, 800W 80+ Platinum Corsair 900D 
MouseMouse PadAudioAudio
Mionix Naos 8200 Razer Pro Solutions Arcam rDAC B&W CM1 
  hide details  
Reply
The Kandalf
(16 items)
 
  
CPUMotherboardGraphicsGraphics
I7 5820K MSI X99S Gaming 7 ASUS R9 280X TOP Crossfire X ASUS R9 280X TOP Crossfire X 
RAMHard DriveOptical DriveOS
Crucial DDR4 2133MHz 8GB (2x4GB) Samsung SpinPoint F1 1TB HP DVD630 Ubuntu 
MonitorKeyboardPowerCase
2x Philips Brilliance 220CW Microsoft Wireless Desktop Elite Keyboard Fractal Design Newton R3, 800W 80+ Platinum Corsair 900D 
MouseMouse PadAudioAudio
Mionix Naos 8200 Razer Pro Solutions Arcam rDAC B&W CM1 
  hide details  
Reply
post #10 of 30
Thread Starter 
Quote:
Originally Posted by i_ame_killer_2 View Post
Hey, thats the beauty of programming. You can achieve the same goal in different ways. Some is easier to read/write, some are faster etc etc. If you got the grade you deserved then no problem.
That one is neither.
Code:
((y > 0) && (y < model.map.TILESIZE) && ((x > model.map.TILESIZE) && (x > ((model.mv.vw-1)*model.map.TILESIZE)) && (x < ((model.mv.vw)*model.map.TILESIZE))))
Lets break this down...

(y > 0) - The mouse not above the panel
(y < model.map.TILESIZE) - The mouse is at most 1 tile length away from the top edge of the panel
(x > model.map.TILESIZE) - The mouse is more than 1 tile length away from left edge of the panel
(x > ((model.mv.vw-1)*model.map.TILESIZE)) - The mouse is less than 1 tile length away from the right edge of the panel
(x < ((model.mv.vw)*model.map.TILESIZE)) - The mouse to the left of the right edge of the panel

That's 9 comparisons involving 2 multiplications, a subtraction and a bunch of unnecessary classes, plus an extra 4 comparisons and another addition and subtraction to handle special cases where the map view is on the edge of the map, and that's only for 1 of the 8 possible directions.

That means 48 comparisons for the ordinal directions, and an additional 28 for the cardinal directions.

Here is what it was replaced with:

Code:
if(x < 15)
                model.mv.scrollX = -1;
            else if (x > model.mv.getWidth() - 15)
                model.mv.scrollX = 1;
            else
                model.mv.scrollX = 0;

            if(y < 15)
                model.mv.scrollY = -1;
            else if(y > model.mv.getHeight()-15)
                model.mv.scrollY = 1;
            else
                model.mv.scrollY = 0;
4 comparisons handling all 8 directions, since technically there are only 2 directions. I set the game to scroll by scrollX and scrollY every tick, so if you want west you set scrollX to -1, if you want south east you set scrollX to 1 and scrollY to 1.

Then I simply set both values to 0 in mouseExited(), which fires every time the mouse leaves the panel, so it won't scroll if the mouse leaves the window.
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Here's a Civilization type game I made